package com.java.ratelimter.advice;

import com.java.ratelimter.common.CommonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class CommonExceptionHandler {

    private static final Logger LOGGER = LoggerFactory.getLogger(CommonExceptionHandler.class);

    @ResponseBody
    @ExceptionHandler(Exception.class)
    public CommonResult handleException(Exception e) {
        LOGGER.error("服务器异常", e);
        return new CommonResult<>("DEMO500", e.getMessage(), false);
    }
}
